def DFS(Adj):
    for u in V:
        if color[u]=='white':
            DFS_visit(u)

def DFS_visit(u):
    global time
    color[u]='grey'
    time=time+1
    d[u]=time
    for v in Adj[u]:
        if color[v]=='white':
            pi[v]=u
            DFS_visit(v)
    color[u]='black'
    time=time+1
    f[u]=time

if __name__=='__main__':
    Adj=[[1,2,3],[2],[],[]]
    V=xrange(len(Adj))
    color=['white']*len(Adj)
    pi=[None]*len(Adj)
    d=[0]*len(Adj)
    f=[0]*len(Adj)
    time=0
    
    print 'Adj:', Adj
    DFS(Adj)
    print 'pi:', pi
    print 'd:', d
    print 'f:', f
    

